package com.kakame.codenews.front.dict.dao;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.kakame.codenews.base.web.dao.JdbcBaseDao;
import com.kakame.codenews.base.web.fast.mapping.common.Dict;

/**
 * 前端字典项读取相关数据层
 * @author 何家明 2018年7月8日 下午5:23:05
 */
@Repository
public class FrontDictDao extends JdbcBaseDao {

	public List<Dict> list(Dict dict) {
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT id, dict_code, dict_desc, dict_grandpa_code, dict_parent_code, dict_code, dict_text, dict_value, status, create_time, create_user_id, update_time, update_user_id ");
		sb.append("  FROM t_common_dict ");
		sb.append(" WHERE dict_grandpa_code != dict_code AND status = 'C' ");
		if(StringUtils.isNotBlank(dict.getDictGrandpaCode())) {
			sb.append("AND dict_grandpa_code = :dictGrandpaCode ");
		}
		if(StringUtils.isNotBlank(dict.getDictParentCode())) {
			sb.append("AND dict_parent_code = :dictParentCode ");
		}
		if(StringUtils.isNotBlank(dict.getDictCode())) {
			sb.append("AND dict_code = :dictCode ");
		}
		if(StringUtils.isNotBlank(dict.getDictValue())) {
		    sb.append("AND dict_value = :dictValue ");
		}
		List<Dict> list = list(sb.toString(), dict);
		return list;
	}

}
